package com.example.cardgame.model

class Card(
    private var suit: String,
    private var rank: String,
    var isChosen: Boolean = false,
    var isMatched: Boolean = false
) {
    companion object {
        val rankStrings = arrayOf("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")
        val validSuits = arrayOf("♥", "♦", "♠", "♣")
    }

    override fun toString(): String {
        return "$suit$rank"
    }

    fun match(otherCards: Array<Card>): Int {
        var score = 0
        when (otherCards.size) {
            1 -> {
                val otherCard = otherCards[0]
                if (otherCard.rank == rank) score = 4
                else if (otherCard.suit == suit) score = 1
            }

            2 -> {
                val first = otherCards[0]
                val second = otherCards[1]
                if (rank == first.rank && rank == second.rank) score = 10
                else if (suit == first.suit && suit == second.suit) score = 3
            }
        }
        return score
    }
}
